package com.huang.core;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;


public class FetchWebContent {
	public  String getWebContent()
	{
		String url = "http://waimai.taobao.com/shop_detail.htm?shopId=406&city=330100";
		StringBuffer buffer = new StringBuffer();
		System.setProperty("sun.net.client.defaultConnectTimeout", "5000");
		System.setProperty("sun.net.client.defaultReadTimeout", "5000");
		int maxLength = 999999999;
		try{
			URL newUrl = new URL(url);
			HttpURLConnection hConnect = (HttpURLConnection) newUrl.openConnection();
		    BufferedReader rd = new BufferedReader(new InputStreamReader(hConnect.getInputStream()));
            int ch;
            for (int length = 0; (ch = rd.read()) > -1; length++)
            {
            	buffer.append((char) ch);
            }
            rd.close();
            hConnect.disconnect();
            return buffer.toString().trim();
                
		}
		catch(Exception e)
		{
			System.out.println(e.getLocalizedMessage());
			
		}
		return "";
	}
	
	private  BufferedWriter writer;
	private  void writeToTxt(String content)
	{
		 try 
		 {
			File f = new File("log.txt");
			writer=new BufferedWriter(new FileWriter(f));
            writer.write(content);
            writer.close();
		 } catch (IOException e) 
		 {
			e.printStackTrace();
		 }
	}
}
